package com.tocea.formation.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

/**
 * @author INSTA
 * 
 */
@Entity
public class Event implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6862596761928858265L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long Id;

	private String name;

	@ManyToOne
	@JoinColumn(name = "creatorOfThisEvent_FK", insertable = false, updatable = false)
	private Person creatorOfThisEvent;

	@ManyToMany(mappedBy = "_eventsVisited")
	private Set<Person> personsInvitedToEvent;

	@ManyToOne
	@JoinColumn(name = "CALENDAR_ID_FK")
	private Calendar associatedCalendar;

	public Event() {

		super();
		// TODO Auto-generated constructor stub
	}
	public Event(String name, Person creator, Calendar _calendar) {

		super();
		this.name = name;
		this.creatorOfThisEvent = creator;
		this.setAssociatedCalendar(_calendar);
	}
	public Long getId() {

		return Id;
	}
	public void setId(Long id) {

		Id = id;
	}
	public String getName() {

		return name;
	}
	public void setName(String name) {

		this.name = name;
	}
	public Person getCreator() {

		return creatorOfThisEvent;
	}
	public void setCreator(Person creator) {

		this.creatorOfThisEvent = creator;
	}
	@Override
	public int hashCode() {

		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((creatorOfThisEvent == null) ? 0 : creatorOfThisEvent
						.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {

		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Event other = (Event) obj;
		if (creatorOfThisEvent == null) {
			if (other.creatorOfThisEvent != null)
				return false;
		} else if (!creatorOfThisEvent.equals(other.creatorOfThisEvent))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	@Override
	public String toString() {

		// TODO Auto-generated method stub
		return "event " + name;
	}
	public Set<Person> getGuests() {
		return personsInvitedToEvent;
	}
	public void setGuests(Set<Person> guests) {
		this.personsInvitedToEvent = guests;
	}
	public Calendar getAssociatedCalendar() {
		return associatedCalendar;
	}
	public void setAssociatedCalendar(Calendar associatedCalendar) {
		this.associatedCalendar = associatedCalendar;
	}
}
